<template>
  <div class="div-main">
    <div class="station-top">
      <el-form :inline="true" style="margin-top: 20px;">
        <el-form-item label="车站所在地：">
          <el-input placeholder="车站所在地(不可填写)" :disabled="true" v-model="address">
            <i slot="prefix" class="el-input__icon el-icon-location-outline"></i>
          </el-input>
        </el-form-item>
        <el-form-item label="车站名：" style="margin-left: 100px;" >
          <el-input placeholder="请输入车站" v-model="stationName">
            <i slot="prefix" class="el-input__icon el-icon-search"></i>
          </el-input>
        </el-form-item>
        <el-form-item style="margin-left: 80px;">
          <el-button type="primary" :loading="loading" @click="setSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    
    <el-table :data="tableData" height=337 style="width: 800px;  margin-bottom: 10px;" stripe
      :header-cell-style="{ background:'#f0f9ff', textAlign: 'center' }"
      :cell-style="{ textAlign: 'center' }">
      <el-table-column type="index" width="80" label="序号">
        </el-table-column>
      <el-table-column prop="trainNumber" label="车次">
      </el-table-column>
      <el-table-column prop="stationStart" label="起始">
      </el-table-column>
      <el-table-column prop="stationEnd" label="终到">
      </el-table-column>
      <el-table-column prop="arriveTime" label="到达时间">
      </el-table-column>
      <el-table-column prop="startTime" label="离开时间">
      </el-table-column>
    </el-table>

    <div class="div-footer">
      <span>总共有： {{ total }} 趟车</span>
    </div>
  </div>
</template>

<script>

export default {
  name: "stationScreen",
  data() {
    return {
      loading: false,
      stationName:'武汉站',
      address:'',
      total:0,
      listData:[]
    }
  },
  methods: {
    setSearch(){
      setTimeout(() =>
        this.getAllTrain(),100
      )
    },
    init(){
      this.listData = [],
      this.total = 0,
      this.address = ''
    },
    getAllTrain(){
      console.log(this.stationName);
      this.init();
      this.request.post('/stationVo/getAllTrain/'+this.stationName) .then(
        response => {
          if (response.data.code === 1) {
            this.listData = response.data.data
            this.total = this.listData.length
            // console.log(response.data);
            this.address = response.data.data[0].stationAddress
            this.$message({
              message: '查询成功',
              type: 'success',
              duration: 1000
            });
          } else {
            this.$message({
              message: '查询出错: ' + response.data.msg,
              type: 'error',
              duration: 1000
            })
          }
        },
        error => {
          console.log(error.message)
        }
      )
    }
  },
  created() {
  },
  computed: {
    tableData(){
      return this.listData
    }
  }
}

</script>

<style scoped>
.div-main {
  display: flex;
  height: 90%; 
  width: 100%;
  flex-direction: column;
  align-items: center;
  flex-wrap: nowrap;
  align-content: center;
}

.station-top {
  border: 1px solid #c4b5fd;
  background-color: #f0f9ff;
  width: 1000px;
  height: 90px;
  margin-bottom: 30px;
  margin-top: 40px;
  text-align: center;
}

.div-footer {
  /* margin-left: 100px; */
  font-size: larger;
  width: 780px;
  display: flex;
  justify-content: space-around;
}

</style>